package com.cloud.entity;

import com.alibaba.fastjson.JSONObject;
import com.cloud.util.CommonUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Henry.Song
 * @version 2020/12/28
 * @description
 */
public class BasicConvertTaskEntity extends JSONObject {

    public Integer getId() {
        return getIntValue("id");
    }

    public void setId(Integer id) {
        put("id", id);
    }

    public String getAlgorithmType() {
        return getString("algorithmType");
    }

    public void setAlgorithmType(String algorithmType) {
        put("algorithmType", algorithmType);
    }

    public String getTaskName() {
        return getString("taskName");
    }

    public void setTaskName(String taskName) {
        put("taskName", taskName);
    }

    public String getTaskStatus() {
        return getString("taskStatus");
    }

    public void setTaskStatus(String taskStatus) {
        put("taskStatus", taskStatus);
    }

    public String getTaskType() {
        return getString("taskType");
    }

    public void setTaskType(String taskType) {
        put("taskType", taskType);
    }

    public List<ConvertTaskFileEntity> getTaskFiles() {

        if (getJSONArray("taskFiles") == null) {
            setTaskFiles(new ArrayList<ConvertTaskFileEntity>());
        }
        List<ConvertTaskFileEntity> files = new ArrayList<ConvertTaskFileEntity>();
        for(Object object : getJSONArray("taskFiles").toArray()) {
            if (object instanceof ConvertTaskFileEntity) {
                files.add((ConvertTaskFileEntity)object);
            } else if (object instanceof Map) {
                ConvertTaskFileEntity fileEntity = new ConvertTaskFileEntity();
                CommonUtil.copyFromMap(fileEntity, (Map)object);
                files.add(fileEntity);

            }
        }
        return files;
    }

    public void setTaskFiles(List<ConvertTaskFileEntity> taskFiles) {
        put("taskFiles", taskFiles);
    }

    public List<ConvertTaskFileEntity> getConvertedTaskFiles() {

        if (getJSONArray("convertedTaskFiles") == null) {
            setConvertedTaskFiles(new ArrayList<ConvertTaskFileEntity>());
        }

        List<ConvertTaskFileEntity> files = new ArrayList<ConvertTaskFileEntity>();
        for(Object object : getJSONArray("taskFiles").toArray()) {
            if (object instanceof ConvertTaskFileEntity) {
                files.add((ConvertTaskFileEntity)object);
            } else if (object instanceof Map) {
                ConvertTaskFileEntity fileEntity = new ConvertTaskFileEntity();
                CommonUtil.copyFromMap(fileEntity, (Map)object);
                files.add(fileEntity);
            }
        }
        return files;
    }

    public void setConvertedTaskFiles(List<ConvertTaskFileEntity> taskFiles) {
        put("convertedTaskFiles", taskFiles);
    }

    public Object getAlgorithmInfo() {
        return getJSONObject("algorithmInfo");
    }

    public void setAlgorithmInfo(Object algorithmInfo) {
        put("algorithmInfo", algorithmInfo);
    }
}

